/********************************************************************
	Copyright (C) 2006-2008 Lensow
	http://www.lensow.com
	Created:	2008/06/14   13:39
	Filename: 	x:\Lensow\Loplayer\src\app\MediaFormats.h
	Author:		Dean

	Purpose:
*********************************************************************/

#pragma once

#include <atlcoll.h>
#include "..\libcore\IGraphBuilder2.h"

class CMediaFormatCategory
{
protected:
	CString m_label, m_specreqnote, m_progid;
	CAtlList<CString> m_exts, m_backupexts;
	bool m_fAudioOnly;
	engine_t m_engine;

public:
	CMediaFormatCategory();
	CMediaFormatCategory(
		CString label, CString CommonExt, CAtlList<CString>& exts, bool fAudioOnly = false,
		CString specreqnote =  _T(""), engine_t e = DirectShow);
	CMediaFormatCategory(
		CString label, CString CommonExt, CString exts, bool fAudioOnly = false,
		CString specreqnote =  _T(""), engine_t e = DirectShow);
	virtual ~CMediaFormatCategory();

	void UpdateData(bool fSave);

	CMediaFormatCategory(const CMediaFormatCategory& mfc);
	CMediaFormatCategory& operator = (const CMediaFormatCategory& mfc);

	void RestoreDefaultExts();
	void SetExts(CAtlList<CString>& exts);
	void SetExts(CString exts);

	bool FindExt(CString ext) const {
		return m_exts.Find(ext.TrimLeft(_T(".")).MakeLower()) != NULL;
	}

	CString GetLabel() const {
		return m_label;
	}
	CString GetFilter() const;
	CString GetExts(bool fAppendEngine = false) const;
	CString GetExtsWithPeriod(bool fAppendEngine = false) const;
	CString GetBackupExtsWithPeriod(bool fAppendEngine = false) const;
	CString GetSpecReqNote() const{
		return m_specreqnote;
	}
	bool IsAudioOnly() const{
		return m_fAudioOnly;
	}
	engine_t GetEngineType() const{
		return m_engine;
	}
	void SetEngineType(engine_t e) {
		m_engine = e;
	}
	CString GetProgId() const{
		return m_progid;
	};
};

class CMediaFormats : public CArray<CMediaFormatCategory>
{
protected:
	engine_t m_iRtspHandler;
	bool m_fRtspFileExtFirst;

public:
	CMediaFormats();
	virtual ~CMediaFormats();

	void UpdateData(bool fSave);

	engine_t GetRtspHandler(bool& fRtspFileExtFirst) const;
	void SetRtspHandler(engine_t e, bool fRtspFileExtFirst);

	bool IsUsingEngine(CString path, engine_t e) const;
	engine_t GetEngine(LPCTSTR lpszPath) const;

	bool FindExt(CString ext, bool fAudioOnly = false) const;

	void GetFilter(CString& filter, CStringArray& mask) const;
	void GetAudioFilter(CString& filter, CStringArray& mask) const;
};
